package com.school;

import org.apache.catalina.filters.RemoteIpFilter;

import java.util.Scanner;



public class StringDemo3 {
    public static void main(String[] args) {
      /* Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str=sc.next();
        //进行遍历
        for(int i=0;i<str.length();i++)
        {
            char c=str.charAt(i);
            System.out.println(c);
        }
        */
        //字符拼接

        int[] arr={1,2,3,4,5};
        String s=arrTostring(arr);
        System.out.println(s);
        System.out.println(reverse(s));

    }

    public static String arrTostring(int[] arr) {
        if (arr == null) {
            return "";
        }
        if (arr.length == 0) {
            return "[]";
        }

        String result="[";
        for(int i=0;i<arr.length;i++){
            if(i==arr.length-1){
                result=result+arr[i];//最后一个元素不需要加“，”
            }else {
                result = result + arr[i] + ",";
            }
        }
        result=result+"]";

        return result;
    }
    //把字符串反转过来54321
    public static String reverse(String s){
        String result="";

        for(int i=s.length()-2;i>=1;i--){
          char c=s.charAt(i);
          result+=c;
        }

        return "["+result+"]";
    }

}
